<?php
/**
 * Created by lzl
 * Date: 2021 2021/10/9
 * Time: 12:42
 */
namespace App\Http\Controllers\Api;


use App\Forms\GoodsForms;
use App\Services\Api\GoodsServices;

class GoodsController extends Controller
{

    /**
     * 商品列表
     * @return mixed
     * @throws \App\Exceptions\RequestException
     */
    public function getList()
    {
        $rules = [
            'page'   => 'required',
            'limit'  => 'required',
            'name'   => 'nullable',
            'cat_id' => 'nullable',
        ];

        $this->validateInput($rules);

        return $this->successOrNodata((new GoodsServices())->getList($this->validated));
    }


    /**
     * 商品详情
     * @return mixed
     * @throws \App\Exceptions\RequestException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     */
    public function getDetail()
    {
        $rules = [
            'id' => 'required|integer'
        ];

        $this->validateInput($rules);

        return $this->success((new GoodsServices())->getDetail($this->validated['id']));
    }


    /**
     * 分类数据
     * @return mixed
     * @throws \App\Exceptions\RequestException
     */
    public function categoryList()
    {
        $rules = [
            'level' => 'nullable', //level存在为二级分类
        ];

        $this->validateInput($rules);

        return $this->success((new GoodsForms())->getCategoryList($this->validated));
    }




}
